package com.itheima.reggie.controller;

import com.itheima.reggie.common.R;
import com.itheima.reggie.pojo.DishDto;
import com.itheima.reggie.service.DishService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/dish")
public class DishController {
    @Autowired
    private DishService dishService;

    @PostMapping
    public R add(@RequestBody DishDto dishDto) {
        R r = dishService.add(dishDto);
        return r;
    }

    @GetMapping("/page")
    public R page(Integer page, Integer pageSize, String name) {
        R r = dishService.page(page, pageSize, name);
        return r;
    }

    @GetMapping("/{id}")
    public R fingDish(@PathVariable Long id) {
        R r = dishService.fingDish(id);
        return r;
    }

    @PutMapping
    public R upData(@RequestBody DishDto dishDto) {
        R r = dishService.upData(dishDto);
        return r;
    }

    @DeleteMapping
    public R removeByIds(Long[] ids) {
        R r = dishService.removeByIds(ids);
        return r;
    }

    @PostMapping("/status/{id}")
    public R status(Long[] ids, @PathVariable Integer id) {
        R r = dishService.status(ids, id);
        return r;
    }

    @GetMapping("/list")
    public R list(Long categoryId) {
        System.out.println("进来了");
        return dishService.list(categoryId);
    }
}
